<?php

class Admin_Model_DbTable_Examination extends Zend_Db_Table_Abstract
{

    protected $_name = 'examinations';

    public function getAllExam(){
    	return $this->fetchAll();
    }
    
    public function getExamByID($examID){
    	return $this->fetchRow("exam_id = $examID");
    }
    
    public function addExam($eName,$eContent,$eAnswer,$eAnswerR,$teacherID,$skillID){
    	$dataExam = array(
    			"exam_name"=>$eName,
    			"exam_content"=>$eContent,
    			"exam_answer"=>$eAnswer,
    			"exam_answer_right"=>$eAnswerR,
    			"teacher_id"=>$teacherID,
    			"skill_id"=>$skillID,
    			"status"=>0
    			);
    	return $this->insert($dataExam);
    }
    
    public function updateExam($eID,$eName,$eContent,$eAnswer,$eAnswerR,$teacherID,$skillID){
    	$dataExam = array(
    			"exam_name"=>$eName,
    			"exam_content"=>$eContent,
    			"exam_answer"=>$eAnswer,
    			"exam_answer_right"=>$eAnswerR,
    			"teacher_id"=>$teacherID,
    			"skill_id"=>$skillID,
    			"status"=>0
    			);
    	return $this->update($dataExam, "exam_id = $eID");
    }
    
    public function activeExam($eID){
    	$exam = $this->fetchRow("exam_id = $eID");
    	if($exam["status"] == 0){
    		return $this->update(array("status"=>1), "exam_id = $eID");
    	}else{
    		return $this->update(array("status"=>0), "exam_id = $eID");
    	}
    }

}

